package com.china08.yxyapi.api.manage.tec.teaching.resource.myCollect;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;

import io.swagger.annotations.ApiOperation;

/**
 * 老师 我的收藏 搜索
 * 
 */
@CrossOrigin
@RestController
public class MyCollectSrhController extends YxyApiBaseController {

    @Autowired
    private YxyResourceService res;

    @ApiOperation(value = "老师收藏资源列表")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/resource/myCollect", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Page<RespModel> precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody ReqModel reqModel) throws IllegalAccessException, InvocationTargetException {
        Pageable pageable = reqModel.getPageable(Direction.fromString(reqModel.sort), "created_date");
        String schoolId = getProfile(request, response).getSchoolId();
        String userId = getProfile(request, response).getId();
        Page<RespModel> page = res.myResourceFavor(userId, schoolId, reqModel.phase, reqModel.subject, reqModel.keyword,
                "ROLE_TEACHER", pageable);
        return page;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        public String phase;
        public String subject;
        public String keyword;
        public String sort = "desc";
    }

    public static class RespModel {
        public String id;
        public String title;
        public String typeName;
        public List<String> bookContentNames;
        public String uploaderSchoolName;
        public String uploaderName;
        public String auditUserName;
        public String auditSchoolName;
        public String uploadTimeFormat;
        public String favorDate;
        public String formatId;
        public String extension;

        public Boolean isVip = false;

        public Integer isHighQualityYx = 0;

        public String getExtension() {
            return extension;
        }

        public void setExtension(String extension) {
            this.extension = extension;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getTypeName() {
            return typeName;
        }

        public void setTypeName(String typeName) {
            this.typeName = typeName;
        }

        public List<String> getBookContentNames() {
            return bookContentNames;
        }

        public void setBookContentNames(List<String> bookContentNames) {
            this.bookContentNames = bookContentNames;
        }

        public String getUploaderSchoolName() {
            return uploaderSchoolName;
        }

        public void setUploaderSchoolName(String uploaderSchoolName) {
            this.uploaderSchoolName = uploaderSchoolName;
        }

        public String getUploaderName() {
            return uploaderName;
        }

        public void setUploaderName(String uploaderName) {
            this.uploaderName = uploaderName;
        }

        public String getAuditUserName() {
            return auditUserName;
        }

        public void setAuditUserName(String auditUserName) {
            this.auditUserName = auditUserName;
        }

        public String getAuditSchoolName() {
            return auditSchoolName;
        }

        public void setAuditSchoolName(String auditSchoolName) {
            this.auditSchoolName = auditSchoolName;
        }

        public String getUploadTimeFormat() {
            return uploadTimeFormat;
        }

        public void setUploadTimeFormat(String uploadTimeFormat) {
            this.uploadTimeFormat = uploadTimeFormat;
        }

        public String getFavorDate() {
            return favorDate;
        }

        public void setFavorDate(String favorDate) {
            this.favorDate = favorDate;
        }

        public String getFormatId() {
            return formatId;
        }

        public void setFormatId(String formatId) {
            this.formatId = formatId;
        }

        public Boolean getIsVip() {
            return isVip;
        }

        public void setIsVip(Boolean isVip) {
            this.isVip = isVip;
        }

        public Integer getIsHighQualityYx() {
            return isHighQualityYx;
        }

        public void setIsHighQualityYx(Integer isHighQualityYx) {
            this.isHighQualityYx = isHighQualityYx;
        }

    }

}
